package com.example.extension;

import akka.actor.*;
import org.springframework.context.ApplicationContext;

public class SpringAkkaExtension extends AbstractExtensionId<SpringAkkaExtension.SpringExt> {

    public static final SpringAkkaExtension SpringAkkaProvider = new SpringAkkaExtension();

    @Override
    public SpringExt createExtension(ExtendedActorSystem system) {
        return new SpringExt();
    }

    public static class SpringExt implements Extension {
        private volatile ApplicationContext applicationContext;

        public void initialize(ApplicationContext applicationContext) {
            this.applicationContext = applicationContext;
        }

        public Props props(String actorBeanName) {
            return Props.create(SpringActorProducer.class, applicationContext, actorBeanName);
        }
    }
}